from PySide6.QtWidgets import (QDialog)
from PySide6.QtCore import (QSettings, Slot, QByteArray)

from laadsOrderTool.ui.ui_settings import Ui_Dialog


class Settings(QDialog):
    """选项设置窗口（对话框）类"""

    def __init__(self):
        super(Settings, self).__init__()
        self._settings = QSettings('laadsOrderTool', 'laadsOrderTool')
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.init_face()

        # 连接信号与槽函数
        self.accepted.connect(self.write_settings)

    def init_face(self):
        self.ui.lineEdit_user.setText(self._settings.value('username'))
        self.ui.lineEdit_passw.setText(self._settings.value('password'))

    @Slot()
    def write_settings(self):
        self._settings.setValue('username', self.ui.lineEdit_user.text())
        self._settings.setValue('password', self.ui.lineEdit_passw.text())
